/* 有N个人要买可乐，每5个空瓶送1瓶，问共需多少瓶？ */
#include <stdio.h>
#include <stdlib.h>

/* 求c瓶可乐最多能满足多少人 */
int person_1(int c)
{
    int i, j, k, *colas, ret;

    colas = malloc(sizeof(int)*(c+1>5?c+1:5));
    colas[0] = 0;
    colas[1] = 1;
    colas[2] = 2;
    colas[3] = 3;
    colas[4] = 5;
    for (i = 5; i < c+1; i++) {
        j = i/5;
        k = i%5;
        colas[i] = i+j+colas[j+k]-j-k;
    }

    ret = colas[c];
    free(colas);
    return ret;
}

int person_2(int c)
{
    int i, last, left;

    last = left = 0;
    for (i = 1; i < c+1; i++) {
        last ++;
        if (left == 3) {
            last ++;
            left = 0;
        }
        else
            left ++;
    }

    return last;
}

/* 求p个人最少需要多少可乐 */
int cola_1(int p)
{
    int i, last;
    
    last = 0;
    for (i = 1; i < p+1; i++) {
        if (i > person_1(last))
            last ++;
    }

    return last;
}

int cola_2(int p)
{
    int i, last;
    
    last = 0;
    for (i = 1; i < p+1; i++) {
        if (i > person_2(last))
            last ++;
    }

    return last;
}

int cola_3(int p)
{
    return p-p/5;
}

int main(int argc, char *argv[])
{
    int n;
    while (1) {
        printf("person: ");
        scanf("%d", &n);
        printf("%d person need %d colas\n", n, cola_1(n));
        printf("%d person need %d colas\n", n, cola_2(n));
        printf("%d person need %d colas\n", n, cola_3(n));
    }
    return 0;
}
